import { dataConfig } from '@/api/modules';
import { nanoid } from 'nanoid';
import type { Fields, SQL } from '../types';

export const useFetchFields = async (sql: SQL, cashierPlatform: string) => {
  let list: Fields[] = [];

  const fetchData = async () => {
    const { data } = await dataConfig({
      ...sql,
      dataType: cashierPlatform,
    });
    list = data.data.map(v => {
      return {
        ...v,
        id: nanoid(),
      };
    });
  };
  await fetchData();
  return list;
};
